package com.whut.transportation.adapter;

import java.util.List;

import com.whut.transportation.R;
import com.whut.transportation.entity.GuDao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class GuDaoAdapter extends BaseAdapter {

	private List<GuDao> gudaos;
	private int resource;
	private LayoutInflater inflater;
	
	public GuDaoAdapter(Context context, List<GuDao> gudaos, int resource) {
		this.gudaos = gudaos;
		this.resource = resource;
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return gudaos.size();
	}

	@Override
	public Object getItem(int position) {
		return gudaos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View con, ViewGroup parent) {
		if(con==null){
			con = inflater.inflate(resource, null);
		}
		TextView guodao_num = (TextView) con.findViewById(R.id.guodao_num);
		TextView total_num = (TextView) con.findViewById(R.id.total_num);
		GuDao gudao = gudaos.get(position);
		guodao_num.setText(gudao.getGudao());
		total_num.setText(String.valueOf(gudao.getTotalNum()));
		return con;
	}
}
